package com.zhz.project.util;

import org.htmlparser.tags.TableColumn;
import org.htmlparser.tags.TableRow;
import org.htmlparser.tags.TableTag;
import org.htmlparser.util.NodeList;

public class HtmlparserUtils {

    public static String getStringValue(NodeList tableList, int tableid, int row, int col) {
        if (tableList.size() < tableid)
            return "";
        TableTag table = (TableTag) tableList.elementAt(tableid);

        TableRow[] rows = table.getRows();
        if (rows.length < row)
            return "";

        TableColumn[] cols = rows[row].getColumns();
        if (cols.length < col)
            return "";

        return cols[col].toPlainTextString();
    }

    public static TableColumn getTableColumnValue(NodeList tableList, int tableid, int row, int col) {
        if (tableList.size() < tableid)
            return null;
        TableTag table = (TableTag) tableList.elementAt(tableid);

        TableRow[] rows = table.getRows();
        if (rows.length < row)
            return null;

        TableColumn[] cols = rows[row].getColumns();
        if (cols.length < col)
            return null;

        return cols[col];
    }

    public static TableColumn getTableColumnValue(TableTag table, int row, int col) {

        TableRow[] rows = table.getRows();
        if (rows.length < row)
            return null;

        TableColumn[] cols = rows[row].getColumns();
        if (cols.length < col)
            return null;

        return cols[col];
    }

}
